package org.sxf.app.sign.utils;

import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;


import org.sxf.app.sign.handler.SignApp;


public class UIUtils {

	public static Context getContext() {
		return SignApp.getInstance();
	}

	public static Resources getResources() {
		return getContext().getResources();
	}

	public static String getString(int id){
		return getResources().getString(id);
	}

	public static void runOnUiThread(Runnable runnable) {
		if (isRunOnMainThread()) {
			runnable.run();
		} else {
			post(runnable);
		}
	}

	public static void post(Runnable runnable) {
		Handler handler = getHandler();
		handler.post(runnable);
	}

	public static void removeCallBacks(Runnable r) {
		getHandler().removeCallbacks(r);
	}

	public static void postDelay(Runnable runnable, long delay) {
		Handler handler = getHandler();
		handler.postDelayed(runnable, delay);
	}

	private static Handler getHandler() {
		return SignApp.getHandler();
	}

	public static boolean isRunOnMainThread() {
		return android.os.Process.myTid() == getMainThreadTid();
	}

	private static long getMainThreadTid() {
		return SignApp.getMainThreadId();
	}
	
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

//	public static void showExist(Context context, String title, String detail){
//		AlertDialog alertDialog = new AlertDialog.Builder(context).setTitle(title)
//				.setMessage(detail)
//				.setPositiveButton(getResources().getString(R.string.confirm), new DialogInterface.OnClickListener() {
//					public void onClick(DialogInterface dialog, int which) {
//						APPHandler.getInstance().exit();
//					}
//				}).create();
//		alertDialog.show();
//	}
}
